/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Persistencia;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author David
 */
public class LectorArchivo {

    private Scanner input;

    public LectorArchivo() {
    }

    public void openFile(String rutaFile) {
        try {

            input = new Scanner(new File(rutaFile));

        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null, "Error creando el archivo");
            System.err.println("Error abriendo el archivo");
            System.exit(1);
        }
    }

    @Override
    public String toString() {
        String s = "";
        while (input.hasNext()) {
            s = s + input.next() + " ";
        }
        return s;
    }

    public Vector toVector() {
        Vector v = new Vector();
        while (input.hasNext()) {
            v.addElement(input.next());
        }
        return v;
    }

    public Scanner getInput() {
        return input;
    }

    public void close() {
        if (input != null) {
            input.close();
        }
    }
}
